import { defineStore } from 'pinia'
import { ref } from 'vue'
import { systemApi } from '@/api/system'

export const useSystemStore = defineStore('system', () => {
  const health = ref({
    status: 'unknown',
    database: 'unknown'
  })

  const stats = ref({
    total: 0,
    pending_audit: 0,
    approved: 0,
    rejected: 0
  })

  // 检查系统健康状态
  const checkHealth = async () => {
    try {
      const data = await systemApi.health()
      health.value = data
      return data
    } catch (error) {
      console.error('获取健康状态失败:', error)
      return null
    }
  }

  // 获取统计信息
  const getStatistics = async () => {
    try {
      const data = await systemApi.statistics()
      if (data.success) {
        stats.value = data.statistics
      }
      return data
    } catch (error) {
      console.error('获取统计信息失败:', error)
      return null
    }
  }

  return {
    health,
    stats,
    checkHealth,
    getStatistics
  }
})


